package com.ruoyi.system.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.web.domain.WebWenzhang;
import com.ruoyi.system.web.service.IWebWenzhangService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-22
 */
@Controller
@RequestMapping("/web/wenzhang")
public class WebWenzhangController extends BaseController
{
    private String prefix = "web/wenzhang";

    @Autowired
    private IWebWenzhangService webWenzhangService;

    @RequiresPermissions("web:wenzhang:view")
    @GetMapping()
    public String wenzhang()
    {
        return prefix + "/wenzhang";
    }

    /**
     * 查询文章信息列表
     */
    @RequiresPermissions("web:wenzhang:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebWenzhang webWenzhang)
    {
        startPage();
        List<WebWenzhang> list = webWenzhangService.selectWebWenzhangList(webWenzhang);
        return getDataTable(list);
    }

    /**
     * 导出文章信息列表
     */
    @RequiresPermissions("web:wenzhang:export")
    @Log(title = "文章信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebWenzhang webWenzhang)
    {
        List<WebWenzhang> list = webWenzhangService.selectWebWenzhangList(webWenzhang);
        ExcelUtil<WebWenzhang> util = new ExcelUtil<WebWenzhang>(WebWenzhang.class);
        return util.exportExcel(list, "文章信息数据");
    }

    /**
     * 新增文章信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文章信息
     */
    @RequiresPermissions("web:wenzhang:add")
    @Log(title = "文章信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebWenzhang webWenzhang)
    {
        return toAjax(webWenzhangService.insertWebWenzhang(webWenzhang));
    }

    /**
     * 修改文章信息
     */
    @RequiresPermissions("web:wenzhang:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebWenzhang webWenzhang = webWenzhangService.selectWebWenzhangById(id);
        mmap.put("webWenzhang", webWenzhang);
        return prefix + "/edit";
    }

    /**
     * 修改保存文章信息
     */
    @RequiresPermissions("web:wenzhang:edit")
    @Log(title = "文章信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebWenzhang webWenzhang)
    {
        return toAjax(webWenzhangService.updateWebWenzhang(webWenzhang));
    }

    /**
     * 删除文章信息
     */
    @RequiresPermissions("web:wenzhang:remove")
    @Log(title = "文章信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        WebWenzhang webWenzhang = new WebWenzhang();
        webWenzhang.setId(Long.parseLong(ids));
        webWenzhang.setDelFlag(1L);
        return toAjax(webWenzhangService.updateWebWenzhang(webWenzhang));
    }
}
